package com.hospital.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hospital.domain.Doctor;
import com.hospital.service.DoctorService;
import com.hospital.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/doctor")
@CrossOrigin(origins = "*",maxAge = 3600)
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @Cacheable(value = "doctor")
    @GetMapping("/getBackGround")
    public R getBackGround(){
        List<Doctor> list = doctorService.list();
        int num1=0,num2=0,num3=0,num4=0,num5=0;
        for(Doctor doctor : list){
            if(doctor.getBackgroundId()==1) num1++;
            if(doctor.getBackgroundId()==2) num2++;
            if(doctor.getBackgroundId()==3) num3++;
            if(doctor.getBackgroundId()==4) num4++;
            if(doctor.getBackgroundId()==5) num5++;
        }
        Map<String,Integer> map = new HashMap<>();
        map.put("中专", num1);
        map.put("专科", num2);
        map.put("本科", num3);
        map.put("硕士", num4);
        map.put("博士", num5);
        return R.ok().put("data", map);
    }
}
